package Z006ClassAndObject.CO004GouZao;

// 什么是构造函数
class Hero {
    String name ;
    float hp ;
    float armor ;
    int moveSpeed;

    public Hero(){ // 无参构造，内容为空
        System.out.println("实例化一个对象的时候，" +
                "必然会调用构造方法！");
    }


    public static void main(String[] args) {
        Hero h = new Hero(); //
    }
}

// 隐式的构造函数
class Hero1{
    String name ;
    float hp ;
    float armor ;
    int moveSpeed;

    public static void main(String[] args) {
        Hero1 garen = new Hero1();
        garen.name = "盖伦";
        garen.hp = 616.34f;
        garen.armor = 30.3f;
        garen.moveSpeed = 350;

        Hero1 teemo = new Hero1();
        teemo.name = "提莫";
        teemo.hp = 385f;
        teemo.armor = 14f;
        teemo.moveSpeed = 330;
    }


}

// 有参的构造函数
class Hero2{
    String name ;
    float hp ;
    float armor ;
    int moveSpeed;

    public Hero2(String heroname){
        name = heroname;
    }

    public static void main(String[] args) {
        Hero2 garen = new Hero2("盖伦");
        // Hero2 teemo = new Hero2();
        // 有参方法创建时，默认的无参构造方法失效
    }
}

// 构造方法的重载
class Hero3{
    String name ;
    float hp ;
    float armor ;
    int moveSpeed;

    public Hero3(){}

    public Hero3(String name){}

    public Hero3(String heroname, float herohp){
        name = heroname;
        hp = herohp;
    }

    public static void main(String[] args) {
        Hero3 garen = new Hero3("盖伦");
        Hero3 teemo = new Hero3("提莫",383);
    }


    }

/**
 * 为Hero设计4个参数的构造方法
 * 这四个参数分别是
 * String heroName
 * float heroHP
 * float heroArmor
 * int heroMoveSpeed
 */
